package com.example.demo.cp13;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

import java.util.concurrent.TimeUnit;
@Slf4j
public class Cp13 {


    private String slowString(String s) {
        System.out.println("slowString called via " + s);
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
        }
        return "OK";
    }

    public void test(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("debug1");
        log.debug("debug1:" + slowString("debug1"));
        stopWatch.stop();
        stopWatch.start("debug2");
        log.debug("debug2:{}", slowString("debug2"));
        stopWatch.stop();
        stopWatch.start("debug3");
        if (log.isDebugEnabled()) {
            log.debug("debug3:{}", slowString("debug3"));
        }
        stopWatch.stop();
    }
}


class TestCp13{
    public static void main(String[] args) {
        Cp13 c = new Cp13();
        c.test();
    }
}